package com.lcxw.hxzbadmin.controller.tixiancontroller;

import com.lcxw.hxzbadmin.entity.requestbean.DealTixianReq;
import com.lcxw.hxzbadmin.entity.requestbean.GetTixianRecordsReq;
import com.lcxw.hxzbadmin.entity.requestbean.RequestBodyBasic;
import com.lcxw.hxzbapi.controller.incomecontroller.TixianRealization;
import com.lcxw.hxzbapi.entity.response.Response;
import com.lcxw.hxzbcommon.common.StringUtil;
import com.lcxw.hxzbcommon.entity.ErrorCode;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/tixian")
public class TixianController {

    @Resource
    TixianRealization tixianRealization;

    //后台查询提现申请记录
    @PostMapping("/getRecords")
    public Response getTixianRecords(@RequestBody GetTixianRecordsReq getTixianRecordsReq) {
        int pageNum = getTixianRecordsReq.getPageNum();
        int pageSize = getTixianRecordsReq.getPageSize();
        Long userId = getTixianRecordsReq.getUserId();
        String startTime = getTixianRecordsReq.getStartTime();
        String endTime = getTixianRecordsReq.getEndTime();
        String status = getTixianRecordsReq.getStatus();
        if (StringUtil.isEmpty(startTime)) {
            startTime = null;
        }
        if (StringUtil.isEmpty(endTime)) {
            endTime = null;
        }
        if (StringUtil.isEmpty(status)) {
            status = null;
        }

        return tixianRealization
            .adminGetRecords(userId, startTime, endTime, status, pageNum, pageSize);
    }

    //处理提现申请
    @PostMapping("/deal")
    public Response dealTixian(@RequestBody DealTixianReq dealTixianReq) {
        int id = dealTixianReq.getId();
        String decision = dealTixianReq.getDecision();
        String orderNumber = dealTixianReq.getOrderNumber();
        String reason = dealTixianReq.getReason();
        if (decision.equals("1") && StringUtil.isEmpty(orderNumber)) {
            return Response.error(ErrorCode.INVALID_PARAM, "如果已打款，必须携带打款的订单号");
        }
        if (decision.equals("2") && StringUtil.isEmpty(reason)) {
            return Response.error(ErrorCode.INVALID_PARAM, "如果拒绝打款，必须携带拒绝打款的原因");
        }
        return tixianRealization.dealTixian(id, decision, orderNumber, reason);

    }

}
